{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c6fec099",
   "metadata": {},
   "source": [
    "# Deploying a custom MCP in Streamable HTTP mode with Ray Serve\n",
    "\n",
    "This tutorial walks through deploying the Weather MCP server in Streamable HTTP mode with Ray Serve and FastAPI, then tests it with a simple Python client and [MCP Inspector](https://github.com/modelcontextprotocol/inspector).\n",
    "\n",
    "MCP supports three transports:\n",
    "\n",
    "* [stdio](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#stdio): Local subprocess with newline-delimited JSON over stdin/stdout. Zero-config but only for local clients.\n",
    "\n",
    "* [SSE (legacy, deprecated)](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse): HTTP+Server-Sent events, now deprecated in favor of a unified HTTP transport.\n",
    "\n",
    "* [Streamable HTTP](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http): A single HTTP endpoint that handles both client→server POSTs and server→client GET/SSE streams. \n",
    "\n",
    "MCP in stdio mode is suitable for local or personal use, and Streamable HTTP brings **remote MCP servers** into action for enterprise and production purposes. You can also [integrate the Claude APP with remote MCP server](https://support.anthropic.com/en/articles/11175166-about-custom-integrations-using-remote-mcp). \n",
    "\n",
    "\n",
    "## Integrate MCP in Streamable HTTP mode with Ray Serve on Anyscale\n",
    "The following architecture diagram illustrates the integrations of custom MCP with Ray Serve and Anyscale Service:\n",
    "\n",
    "<img\n",
    "  src=\"https://agent-and-mcp.s3.us-east-2.amazonaws.com/mcp/diagrams/custom_ray_serve_mcp.png\"\n",
    "  alt=\"MCP Gateway with Ray Serve Architecture\"\n",
    "  style=\"width:45%; display: block; margin: 0 auto;\"\n",
    "/>\n",
    "\n",
    "Integrating MCP in Streamable HTTP mode with Ray Serve on Anyscale delivers comprehensive scalability and production-grade capabilities for your AI services through two complementary layers of features:\n",
    "\n",
    "**Ray Serve capabilities:**\n",
    "\n",
    "* **Autoscaling**: Ray Serve automatically adjusts the number of replicas based on traffic demand, ensuring your service handles increased load while maintaining responsiveness during peak usage periods.\n",
    "* **Load balancing**: Ray Serve intelligently distributes incoming requests across available replicas, preventing any single instance from becoming overwhelmed and maintaining consistent performance.\n",
    "* **Observability**: Built-in monitoring capabilities provide visibility into your service's performance, including request metrics, resource utilization, and system health indicators.\n",
    "* **Fault tolerance**: Ray Serve automatically detects and recovers from failures by restarting failed components and redistributing requests to healthy replicas, ensuring continuous service availability.\n",
    "* **Composition**: Build complex services by orchestrating multiple deployments into a single pipeline, allowing you to chain preprocessing, model inference, postprocessing, and custom logic seamlessly.\n",
    "\n",
    "**Anyscale service additional benefits:**\n",
    "\n",
    "* **Production ready**: Anyscale provides enterprise-grade infrastructure management, automated deployments that make your MCP service ready for real-world production traffic.\n",
    "* **[High availability](https://docs.anyscale.com/platform/services/faq#does-services-support-multiple-availability-zones-for-high-availability)**: Advanced Availability Zone aware scheduling mechanisms and zero-downtime rolling updates to ensure your service maintains high availability.\n",
    "* **[Logging](https://docs.anyscale.com/monitoring/accessing-logs) and [tracing](https://docs.anyscale.com/monitoring/tracing)**: Enhanced observability with comprehensive logging, distributed tracing, and real-time monitoring dashboards that provide deep insights into request flows and system performance.\n",
    "* **[Head node fault tolerance](https://docs.anyscale.com/platform/services/head-node-ft/)**: Additional resilience through managed head node redundancy, protecting against single points of failure in your Ray cluster's coordination layer.\n",
    "\n",
    "This combination ensures your MCP service operates with enterprise-level reliability while optimizing resource efficiency and cost-effectiveness.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28400dd1",
   "metadata": {},
   "source": [
    "## Prerequisites\n",
    "- Ray [serve], already included in the base Docker image\n",
    "- MCP Python library \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35274073",
   "metadata": {},
   "source": [
    "### Dependencies\n",
    "**Install the required Python packages and Podman:**\n",
    "```bash\n",
    "pip install  mcp==1.11.0 asyncio==3.4.3 pydantic==2.9.2\n",
    "```\n",
    "\n",
    "**Alternative: Docker image for Ray Serve deployment**\n",
    "\n",
    "You can also [build a Docker image for deployment on Anyscale](https://docs.anyscale.com/configuration/dependency-management/dependency-byod/) using the [Dockerfile in this code repo](./Dockerfile). \n",
    "\n",
    "**Note**\n",
    " This Docker image is provided solely to deploy the MCP with Ray Serve. \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8301ebe",
   "metadata": {},
   "source": [
    "## 1. Create the deployment script\n",
    "\n",
    "This script sets up a scalable weather alert and forecast service using FastAPI, FastMCP, and Ray Serve.\n",
    "\n",
    "It defines two asynchronous tools—get_alerts and get_forecast—which retrieve data from the National Weather Service, following the tutorial available at: https://modelcontextprotocol.io/quickstart/server.\n",
    "\n",
    "Use a FastAPI app configured with Streamable HTTP mode to expose these tools to support real-time, bidirectional communication. \n",
    "\n",
    "By default, this automatically creates an **`'/mcp'`** endpoint: `app.mount(\"/\", mcp.streamable_http_app())`.\n",
    "\n",
    "Finally, deploy the entire app using Ray Serve, enabling dynamic autoscaling and distributed inference when you launch it with `serve run`.\n",
    "\n",
    "### Important note:\n",
    "\n",
    "Ray Serve currently only supports the **stateless HTTP mode** in MCP. Because each replica doesn't share session state, enabling **stateless_http=True** prevents “session not found” errors when multiple replicas are running:\n",
    "\n",
    "`mcp = FastMCP(\"weather\", stateless_http=True)`\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5256d1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Save the following code as `weather_mcp_ray.py`.\n",
    "from typing import Any\n",
    "import httpx\n",
    "from fastapi import FastAPI\n",
    "from mcp.server.fastmcp import FastMCP\n",
    "import ray\n",
    "from ray import serve\n",
    "from contextlib import asynccontextmanager\n",
    "\n",
    "# Constants.\n",
    "NWS_API_BASE = \"https://api.weather.gov\"\n",
    "USER_AGENT = \"weather-app/1.0\"\n",
    "\n",
    "# Helper functions.\n",
    "async def make_nws_request(url: str) -> dict[str, Any] | None:\n",
    "    headers = {\"User-Agent\": USER_AGENT, \"Accept\": \"application/geo+json\"}\n",
    "    async with httpx.AsyncClient(timeout=30.0) as client:\n",
    "        try:\n",
    "            resp = await client.get(url, headers=headers)\n",
    "            resp.raise_for_status()\n",
    "            return resp.json()\n",
    "        except Exception:\n",
    "            return None\n",
    "\n",
    "\n",
    "def format_alert(feature: dict) -> str:\n",
    "    props = feature[\"properties\"]\n",
    "    return (\n",
    "        f\"Event: {props.get('event', 'Unknown')}\\n\"\n",
    "        f\"Area: {props.get('areaDesc', 'Unknown')}\\n\"\n",
    "        f\"Severity: {props.get('severity', 'Unknown')}\\n\"\n",
    "        f\"Description: {props.get('description', 'No description available')}\\n\"\n",
    "        f\"Instructions: {props.get('instruction', 'No specific instructions provided')}\"\n",
    "    )\n",
    "\n",
    "# Instantiate FastMCP and register tools via decorators.\n",
    "mcp = FastMCP(\"weather\", stateless_http=True)\n",
    "\n",
    "@mcp.tool()\n",
    "async def get_alerts(state: str) -> str:\n",
    "    \"\"\"Fetch active alerts for a given state code (e.g., 'CA').\"\"\"\n",
    "    url = f\"{NWS_API_BASE}/alerts/active/area/{state}\"\n",
    "    data = await make_nws_request(url)\n",
    "    if not data or \"features\" not in data:\n",
    "        return \"Unable to fetch alerts or no alerts found.\"\n",
    "    features = data[\"features\"]\n",
    "    if not features:\n",
    "        return \"No active alerts for this state.\"\n",
    "    return \"\\n---\\n\".join(format_alert(f) for f in features)\n",
    "\n",
    "@mcp.tool()\n",
    "async def get_forecast(latitude: float, longitude: float) -> str:\n",
    "    \"\"\"Fetch a 5-period weather forecast for given lat/lon.\"\"\"\n",
    "    points_url = f\"{NWS_API_BASE}/points/{latitude},{longitude}\"\n",
    "    points_data = await make_nws_request(points_url)\n",
    "    if not points_data or \"properties\" not in points_data:\n",
    "        return \"Unable to fetch forecast data for this location.\"\n",
    "\n",
    "    forecast_url = points_data[\"properties\"].get(\"forecast\")\n",
    "    if not forecast_url:\n",
    "        return \"No forecast URL found for this location.\"\n",
    "\n",
    "    forecast_data = await make_nws_request(forecast_url)\n",
    "    if not forecast_data or \"properties\" not in forecast_data:\n",
    "        return \"Unable to fetch detailed forecast.\"\n",
    "\n",
    "    periods = forecast_data[\"properties\"].get(\"periods\", [])\n",
    "    if not periods:\n",
    "        return \"No forecast periods available.\"\n",
    "\n",
    "    parts: list[str] = []\n",
    "    for p in periods[:5]:\n",
    "        parts.append(\n",
    "            f\"{p['name']}:\\nTemperature: {p['temperature']}°{p['temperatureUnit']}\\n\" +\n",
    "            f\"Wind: {p['windSpeed']} {p['windDirection']}\\n\" +\n",
    "            f\"Forecast: {p['detailedForecast']}\"\n",
    "        )\n",
    "    return \"\\n---\\n\".join(parts)\n",
    "\n",
    "## FastAPI app and Ray Serve setup.\n",
    "@asynccontextmanager\n",
    "async def lifespan(app: FastAPI):\n",
    "    # 1) Mount the MCP app.\n",
    "    app.mount(\"/\", mcp.streamable_http_app())\n",
    "\n",
    "    # 2) Enter the session_manager's context.\n",
    "    async with mcp.session_manager.run():\n",
    "        yield\n",
    "\n",
    "fastapi_app = FastAPI(lifespan=lifespan)\n",
    "\n",
    "@serve.deployment(\n",
    "    autoscaling_config={\n",
    "        \"min_replicas\": 1, \n",
    "        \"max_replicas\": 20, \n",
    "        \"target_ongoing_requests\": 5\n",
    "        },\n",
    "    ray_actor_options={\"num_cpus\": 0.2}\n",
    ")\n",
    "@serve.ingress(fastapi_app)\n",
    "class WeatherMCP:\n",
    "    def __init__(self):\n",
    "        pass\n",
    "       \n",
    "\n",
    "# Ray Serve entry point.\n",
    "app = WeatherMCP.bind()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e7dbb50",
   "metadata": {},
   "source": [
    "## 2. Run Ray Serve in the terminal\n",
    "\n",
    "```bash\n",
    "serve run  weather_mcp_ray:app\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ace30082",
   "metadata": {},
   "source": [
    "## 3. Test with a Python client\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e07ff37",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import asyncio\n",
    "import httpx\n",
    "from mcp.client.streamable_http import streamablehttp_client\n",
    "from mcp import ClientSession\n",
    "\n",
    "BASE_URL = \"http://localhost:8000\"\n",
    "STREAM_URL = f\"{BASE_URL}/mcp\"\n",
    "\n",
    "async def main() -> None:\n",
    "    async with streamablehttp_client(STREAM_URL) as (r, w, _):\n",
    "        async with ClientSession(r, w) as session:\n",
    "            await session.initialize()\n",
    "\n",
    "            tools = await session.list_tools()\n",
    "            print(\"Available tools:\")\n",
    "            for t in tools.tools:\n",
    "                print(f\"  • {t.name}: {t.description}\")\n",
    "            print()\n",
    "\n",
    "            alerts = await session.call_tool(\n",
    "                name=\"get_alerts\", arguments={\"state\": \"CA\"}\n",
    "            )\n",
    "            print(\"=== Active Alerts for CA ===\")\n",
    "            print(alerts.content[0].text)\n",
    "            print()\n",
    "\n",
    "            forecast = await session.call_tool(\n",
    "                name=\"get_forecast\",\n",
    "                arguments={\"latitude\": 34.05, \"longitude\": -118.24},\n",
    "            )\n",
    "            print(\"=== 5-Period Forecast for LA ===\")\n",
    "            print(forecast.content[0].text)\n",
    "            print()\n",
    "\n",
    "\n",
    "# ──────── How to run in Jupyter Notebook ────────────────────────────\n",
    "# await main()\n",
    "# ────────────────────────────────────────────────────────────────────\n",
    "\n",
    "\n",
    "# ──────── How to run as a standalone Python script ──────────────────\n",
    "# import asyncio\n",
    "#\n",
    "# if __name__ == \"__main__\":\n",
    "#     # Create and run the event loop\n",
    "#     asyncio.run(main())\n",
    "# ────────────────────────────────────────────────────────────────────"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48b4e822",
   "metadata": {},
   "source": [
    "### To terminate Ray serve:\n",
    "\n",
    "```bash\n",
    "serve shutdown --yes\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49e5fb6e",
   "metadata": {},
   "source": [
    "## 4.  Production deployment with Anyscale service\n",
    "\n",
    "For production deployment, use Anyscale services to deploy the Ray Serve app to a dedicated cluster without modifying the code. Anyscale ensures scalability, fault tolerance, and load balancing, keeping the service resilient against node failures, high traffic, and rolling updates.\n",
    "\n",
    "Use the following command to deploy the service:\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7e7f38e",
   "metadata": {},
   "source": [
    "```bash\n",
    "anyscale service deploy weather_mcp_ray:app --name=weather_mcp_service\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cacfcf4",
   "metadata": {},
   "source": [
    "## 5. Query the production service\n",
    "\n",
    "When you deploy, you expose the service to a publicly accessible IP address, which you can send requests to.\n",
    "\n",
    "In the preceding cell’s output, copy your API_KEY and BASE_URL. As an example, the values look like the following:\n",
    "\n",
    "* BASE_URL = \"https://multi-mcp-tool-service-jgz99.cld-kvedzwag2qa8i5bj.s.anyscaleuserdata.com\"\n",
    "* TOKEN = \"z3RIKzZwHDF9sV60o7M48WsOY1Z50dsXDrWRbxHYtPQ\"\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "Fill in the following placeholder values for the BASE_URL and API_KEY in the following Python requests object:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "596b0d7d",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import asyncio\n",
    "import httpx\n",
    "from mcp.client.streamable_http import streamablehttp_client\n",
    "from mcp import ClientSession\n",
    "\n",
    "BASE_URL = \"https://weather-mcp-service-jgz99.cld-kvedzwag2qa8i5bj.s.anyscaleuserdata.com\" # Replace with your own URL\n",
    "TOKEN = \"SonDp89sqyElLcVX1SLcMu1qeVfqyVOpfKjL7D0vjrM\" # Replace with your token\n",
    "STREAM_URL = f\"{BASE_URL}/mcp\"\n",
    "\n",
    "# # Common headers for auth.\n",
    "headers = {\n",
    "    \"Authorization\": f\"Bearer {TOKEN}\"\n",
    "}\n",
    "\n",
    "async def main() -> None:\n",
    "\n",
    "    # Pass the headers into the HTTP client so the server sees a valid JSON-RPC + SSE handshake.\n",
    "    async with streamablehttp_client(STREAM_URL, headers=headers) as (r, w, _):\n",
    "        async with ClientSession(r, w) as session:\n",
    "            # This now sends the JSON-RPC \"initialize\" under the hood.\n",
    "            await session.initialize()\n",
    "\n",
    "            tools = await session.list_tools()\n",
    "            print(\"Available tools:\")\n",
    "            for t in tools.tools:\n",
    "                print(f\"  • {t.name}: {t.description}\")\n",
    "            print()\n",
    "\n",
    "            alerts = await session.call_tool(\n",
    "                name=\"get_alerts\", arguments={\"state\": \"CA\"}\n",
    "            )\n",
    "            print(\"=== Active Alerts for CA ===\")\n",
    "            print(alerts.content[0].text)\n",
    "            print()\n",
    "\n",
    "            forecast = await session.call_tool(\n",
    "                name=\"get_forecast\",\n",
    "                arguments={\"latitude\": 34.05, \"longitude\": -118.24},\n",
    "            )\n",
    "            print(\"=== 5-Period Forecast for LA ===\")\n",
    "            print(forecast.content[0].text)\n",
    "            print()\n",
    "\n",
    "# ──────── How to run in Jupyter Notebook ────────────────────────────\n",
    "# await main()\n",
    "# ────────────────────────────────────────────────────────────────────\n",
    "\n",
    "\n",
    "# ──────── How to run as a standalone Python script ──────────────────\n",
    "# import asyncio\n",
    "#\n",
    "# if __name__ == \"__main__\":\n",
    "#     # Create and run the event loop\n",
    "#     asyncio.run(main())\n",
    "# ────────────────────────────────────────────────────────────────────"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b23541c",
   "metadata": {},
   "source": [
    "## 6. Test the service with MCP inspector\n",
    "\n",
    "The **MCP inspector** is a developer tool for testing and debugging MCP servers: https://github.com/modelcontextprotocol/inspector.\n",
    "\n",
    "\n",
    "### On your local machine\n",
    "\n",
    "Install Node.js and NPM: https://nodejs.org/en/download\n",
    "\n",
    "\n",
    "Launch the MCP Inspector. **Make sure your MCP inspector version is = 0.16.1**:\n",
    "\n",
    "```bash\n",
    "npx -y @modelcontextprotocol/inspector@0.16.1\n",
    "```\n",
    "\n",
    "You should see the message: `🔍 MCP Inspector is up and running at http://127.0.0.1:6274`.\n",
    "\n",
    "Then open the link \"http://127.0.0.1:6274\" and configure the following:\n",
    "\n",
    "* Transport Type: Streamable HTTP\n",
    "* URL: https://weather-mcp-service-jgz99.cld-kvedzwag2qa8i5bj.s.anyscaleuserdata.com/mcp\n",
    "* Bearer Token: SonDp89sqyElLcVX1SLcMu1qeVfqyVOpfKjL7D0vjrM\n",
    "\n",
    "**Note**: \n",
    "* Include the **\"/mcp\"** in your URL, otherwise the connection fails.  \n",
    "* After MCP Inspector is up and running, you would receive the message such as: \"http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=f8c738c6788295b7d71831ac89f64faea2659af8b4f460038b4c6156ee8e72fd\" You need to enter the Proxy Session Token in the MCP inspector as well. Otherwise you would encounter error \"Proxy Authentication Required\".\n",
    "\n",
    "<img\n",
    "  src=\"https://agent-and-mcp.s3.us-east-2.amazonaws.com/mcp/diagrams/mcp_inspector_connection.png\"\n",
    "  alt=\"MCP Inspector Connection\"\n",
    "  style=\"width:30%;\"\n",
    "/>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a2f2d03",
   "metadata": {},
   "source": [
    "You can see that it's connected. Then, go to **Tools** and click **`List Tools`**, to see that two tools are available.\n",
    "\n",
    "After that, you can select a tool and test it. Once you click **`Run Tool`**, you see the **`Tool Result`**.\n",
    "\n",
    "<img\n",
    "  src=\"https://agent-and-mcp.s3.us-east-2.amazonaws.com/mcp/diagrams/mcp_weather_alerts_results.png\"\n",
    "  alt=\"MCP Weather Alerts Results\"\n",
    "  style=\"width:80%;\"\n",
    "/>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1ee02dc",
   "metadata": {},
   "source": [
    "## 7. Terminate the Anyscale Service\n",
    "After testing the service, you can shutdown the serive with this command:\n",
    "```bash\n",
    "anyscale service terminate --name=weather_mcp_service\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "859dea84",
   "metadata": {},
   "source": [
    "## 8. Try it yourself with a translator MCP example with Ray Serve using GPU\n",
    "\n",
    "Run the following code to deploy your own service using fractional GPUs and verify it with the MCP Inspector."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7648c849",
   "metadata": {},
   "source": [
    "\n",
    "Here is the code from `translator_mcp_ray.py`:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7cd4645",
   "metadata": {},
   "source": [
    "```python\n",
    "import asyncio\n",
    "from fastapi import FastAPI\n",
    "from mcp.server.fastmcp import FastMCP\n",
    "from contextlib import asynccontextmanager\n",
    "from ray import serve\n",
    "from transformers import pipeline\n",
    "\n",
    "# ---------------------------------------------------------------------\n",
    "# 1. FastMCP business logic for translation\n",
    "# ---------------------------------------------------------------------\n",
    "mcp = FastMCP(\"translator\", stateless_http=True)\n",
    "\n",
    "# Pre-load the translation model (English → French).\n",
    "translator_pipeline = pipeline(\"translation_en_to_fr\", model=\"t5-small\")\n",
    "\n",
    "@mcp.tool()\n",
    "async def translate(text: str) -> str:\n",
    "    \"\"\"Translate English text to French.\"\"\"\n",
    "    loop = asyncio.get_event_loop()\n",
    "    # Offload the sync pipeline call to a thread to avoid blocking the event loop.\n",
    "    result = await loop.run_in_executor(None, translator_pipeline, text)\n",
    "    return result[0][\"translation_text\"]\n",
    "\n",
    "\n",
    "\n",
    "## FastAPI app and Ray Serve setup.\n",
    "@asynccontextmanager\n",
    "async def lifespan(app: FastAPI):\n",
    "    # 1) Mount the MCP app.\n",
    "    app.mount(\"/\", mcp.streamable_http_app())\n",
    "\n",
    "    # 2) Enter the session_manager's context.\n",
    "    async with mcp.session_manager.run():\n",
    "        yield\n",
    "\n",
    "fastapi_app = FastAPI(lifespan=lifespan)\n",
    "\n",
    "@serve.deployment(\n",
    "    autoscaling_config={\n",
    "        \"min_replicas\": 2,\n",
    "        \"max_replicas\": 20,\n",
    "        \"target_ongoing_requests\": 10\n",
    "    },\n",
    "    ray_actor_options={\"num_gpus\": 0.5, \n",
    "    'runtime_env':{\n",
    "        \"pip\": [\n",
    "            \"transformers\",   \n",
    "            \"torch\"              \n",
    "        ]\n",
    "    }}\n",
    ")\n",
    "@serve.ingress(fastapi_app)\n",
    "class TranslatorMCP:\n",
    "    def __init__(self):\n",
    "        pass\n",
    "       \n",
    "\n",
    "# Ray Serve entry point.\n",
    "app = TranslatorMCP.bind()\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ffedf36",
   "metadata": {},
   "source": [
    " If successful, you see the `Tool Result` similar to the image below:\n",
    " \n",
    "<img\n",
    "  src=\"https://agent-and-mcp.s3.us-east-2.amazonaws.com/mcp/diagrams/mcp_translator_inspector.png\"\n",
    "  alt=\"MCP Translator Inspector\"\n",
    "  style=\"width:80%;\"\n",
    "/>\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
